home *** CD-ROM | disk | FTP | other *** search
- /*
- * QueryDevice.c
- * © 1999 Apple Computer, Inc.
- *
- * Sample showing the use of the USBPowerShim API
- * Comments: Tom Clark, tclark@apple.com
- *
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <USB.h>
- #include "PowerClass.h"
-
- int main(void)
- {
- OSStatus status = noErr;
- PowerDeviceDescriptor device;
- UInt16 x = 0;
- UInt32 choice = 0;
- UInt32 ref;
- UInt32 collection;
- UInt32 page;
- UInt32 usage;
- SInt32 value;
-
- device.reference = kNoDeviceRef; // Prime the search
- do
- {
- status = GetNextPowerDevice (&device);
- if (noErr == status)
- {
- printf ("Device Found. Reference: 0x%X\n", device.reference);
- }
- } while (noErr == status);
-
-
- printf ("\nDevice Reference To Query: ");
- scanf ("%x", &ref);
-
- while (1)
- {
-
- printf ("\n[1] Get Usage Data\n");
- printf ("[2] Set Usage Data\n");
- printf ("Choice: ");
- scanf ("%d", &choice);
-
- switch (choice)
- {
- case (1):
- printf ("\nCollection: ");
- scanf ("%x", &collection);
- printf ("Usage Page: ");
- scanf ("%x", &page);
- printf ("Usage: ");
- scanf ("%x", &usage);
- status = USBPowerGetUsageData (ref, collection, page, usage, &value); // Ask the shim for the info
- if (noErr == status)
- printf ("Value Returned: %d\n", value);
- else if (status == kUSBPending)
- {
- status = USBPowerGetUsageData (ref, collection, page, usage, &value); // Ask the shim for the info
- if (noErr == status)
- printf ("Value Returned: %d\n", value);
- else
- printf ("Error: %d\n", status);
- }
- else
- printf ("Error: %d\n", status);
- break;
- case (2):
- printf ("\nCollection: ");
- scanf ("%x", &collection);
- printf ("Usage Page: ");
- scanf ("%x", &page);
- printf ("Usage: ");
- scanf ("%x", &usage);
- printf ("Value: ");
- scanf ("%d", &value);
- status = USBPowerSetUsageData (ref, collection, page, usage, value);
- printf ("Status Returned: %d\n", status);
- break;
- default:
- break;
-
- }
-
- }
-
- return 0;
- }
-
-